-------------------------------------------------------------
--					Add Procedure
-------------------------------------------------------------
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Products_SaveProducts]') AND type in (N'P', N'PC'))
BEGIN
DROP PROCEDURE [Products_SaveProducts]
END
GO

Create Procedure [dbo].[Products_SaveProducts]
(
	@ProductName nvarchar(max),
	@ProductDescription nvarchar(max)
)
AS
	if exists(select * from Products WITH(NOLOCK) where ProductName = @ProductName)
		update Products set
		ProductName=@ProductName,
		ProductDescription=@ProductDescription,
		UpdateDate=GETDATE()
		where ProductName = @ProductName;
	else
		insert into Products
		(
			ProductName,
			ProductDescription,
			IsDeleted,
			CreationDate,
			UpdateDate
		) 
		values
		(
			@ProductName,
			@ProductDescription,
			0,
			GETDATE(), 
			GETDATE() 
		)
	